package com.example.test.operate.resource;

import com.example.test.operate.POJO.PO.OperateUserInfoPO;
import com.example.test.operate.service.IOperateUserInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <desc>
 *
 * </desc>
 *
 * @createDate 2021-07-19
 */
@RestController
public class OperateUserInfoServiceResource {

    @Autowired
    IOperateUserInfoService iOperateUserInfoService;

    /**
     * <desc>
     *          人员列表
     * </desc>
     *
     * @param
     * @return
     * @author liuyu
     * @createDate
     */
    @RequestMapping(path = "/operate/userinfo/list")
    public List<OperateUserInfoPO> getList(OperateUserInfoPO operateUserInfoPO){
        System.out.println(operateUserInfoPO);
        return iOperateUserInfoService.getList(operateUserInfoPO);
    }

/**
 * <desc>
 *      列表分页数据
 * </desc>
 *
 * @param
 * @return
 * @author liuyu
 * @createDate 2021-07-26
 */
    @RequestMapping(path = "/operate/userinfo/page2")
    public PageInfo<OperateUserInfoPO> getPageList(@RequestParam("currentPage") Integer currentPage,
                                               @RequestParam ("pageSize") Integer pageSize,
                                               OperateUserInfoPO operateUserInfoPO){

       //去掉输入字符串头尾的空白符号
        if(operateUserInfoPO.getUserName() != null || operateUserInfoPO.getGroupName() != null)
        {
            operateUserInfoPO.setUserName(operateUserInfoPO.getUserName().trim());
            operateUserInfoPO.setGroupName(operateUserInfoPO.getGroupName().trim());
        }
        PageHelper.startPage(currentPage,pageSize);
        List<OperateUserInfoPO> operateUserInfoPOS = iOperateUserInfoService.getList(operateUserInfoPO);
        PageInfo<OperateUserInfoPO>  pageInfo = new PageInfo<>(operateUserInfoPOS );
        return pageInfo;

    }

    /**
     * <desc>
     *
     * </desc>
     *
     * @param
     * @return
     * @author liuyu
     * @createDate 2021-07-26
     */
    @RequestMapping(path = "/operate/userinfo/getuserids")
    String[] getUserIds(String roleId){
        return iOperateUserInfoService.getUserIdByRoleId(roleId);
    }
}
